package com.ck.ck_back.controller;

import com.ck.ck_back.pojo.Result;
import com.ck.ck_back.service.msgservice;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/msg")
public class MsgController {
    @Resource
    private msgservice msgserviceimpl;

    @PostMapping("/id_success")
    public Object id_success(String openid){
        int result = msgserviceimpl.identitly_success(openid);
        if (result == 1){
            return Result.success();
        }else if (result == 2){
            return Result.failure("增加错误");
        }else {
            return Result.failure("参数错误");
        }
    }

    @PostMapping("/id_fail")
    public Object id_fail(String openid, String msg){
        int result = msgserviceimpl.identitly_fail(openid, msg);
        if (result == 1){
            return Result.success();
        }else if (result == 2){
            return Result.failure("增加错误");
        }else {
            return Result.failure("参数错误");
        }
    }

    @PostMapping("/article_success")
    public Object article_success(String openid,String article_title){
        int result = msgserviceimpl.article_success(openid,article_title);
        if (result == 1){
            return Result.success();
        }else if (result == 2){
            return Result.failure("增加错误");
        }else {
            return Result.failure("参数错误");
        }
    }

    @PostMapping("/article_fail")
    public Object article_fail(String openid,String article_title, String msg){
        int result = msgserviceimpl.airticle_fail(openid,article_title,msg);
        if (result == 1){
            return Result.success();
        }else if (result == 2){
            return Result.failure("增加错误");
        }else {
            return Result.failure("参数错误");
        }
    }

    @PostMapping("/getmsg")
    public Object getmsg(String openid){
        return Result.success(msgserviceimpl.getallmsg(openid));
    }
}
